package com.yjhb.android.sbz.tool;

import android.animation.Animator;
import android.animation.AnimatorListenerAdapter;
import android.animation.ObjectAnimator;
import android.view.View;

/**
 * 创建者 zx
 * 创建时间 2020/9/23 11:12
 *
 * 动画工具类
 */
public class AnimTool {
    private static final String TAG = "AnimTool";
    //左右摇摆动画
    public static void setWaverAnim(View view) {
        final ObjectAnimator animator1 = ObjectAnimator.ofFloat(view, "rotation", -15, 15)
                .setDuration(200);
        final ObjectAnimator animator2 = ObjectAnimator.ofFloat(view, "rotation", 15, -15)
                .setDuration(200);
        final ObjectAnimator animator4 = ObjectAnimator.ofFloat(view, "rotation", -15, 15)
                .setDuration(200);
        final ObjectAnimator animator5 = ObjectAnimator.ofFloat(view, "rotation", 15, -15)
                .setDuration(200);
        final ObjectAnimator animator6 = ObjectAnimator.ofFloat(view, "rotation", -15, 15)
                .setDuration(200);
        final ObjectAnimator animator7 = ObjectAnimator.ofFloat(view, "rotation", 15, -15)
                .setDuration(200);
        final ObjectAnimator animator3 = ObjectAnimator.ofFloat(view, "rotation", -15, 0)
                .setDuration(100);
        animator1.addListener(new AnimatorListenerAdapter() {
            @Override
            public void onAnimationEnd(Animator animation) {
                animator2.start();
            }
        });
        animator2.addListener(new AnimatorListenerAdapter() {
            @Override
            public void onAnimationEnd(Animator animation) {
                animator4.start();
            }
        });
        animator4.addListener(new AnimatorListenerAdapter() {
            @Override
            public void onAnimationEnd(Animator animation) {
                animator5.start();
            }
        });
        animator5.addListener(new AnimatorListenerAdapter() {
            @Override
            public void onAnimationEnd(Animator animation) {
                animator6.start();
            }
        });
        animator6.addListener(new AnimatorListenerAdapter() {
            @Override
            public void onAnimationEnd(Animator animation) {
                animator7.start();
            }
        });
        animator7.addListener(new AnimatorListenerAdapter() {
            @Override
            public void onAnimationEnd(Animator animation) {
                animator3.start();
            }
        });
        animator3.addListener(new AnimatorListenerAdapter() {
            @Override
            public void onAnimationEnd(Animator animation) {
                animator1.setStartDelay(3 * 1000);
                animator1.start();
            }
        });

        animator1.start();
    }

}
